/*衣服尺寸选择*/
//console.debug($(this).attr('alt'));//用来调试
$(function(){
    $(".attrs li span").click(function(){
        //var price=$("div.pro_price span").text();
        $(this).parents("ul").siblings("strong").text(  $(this).text() );
        //console.debug(allprice);//用来调试

        upd_price();
    })
})
function upd_price()
{

    var base =parseFloat($('#base').val());
    var total_price = base;//获取选中的产品价格
    var selecteds = $('.attrs .selected');
    var attr_id="";
    selecteds.each(function () {
        var price = parseFloat($(this).children('span').attr('datavalue'));
        attr_id += parseFloat($(this).children('span').attr('alt'))+',';
        var attr_name = $(this).children('span').attr('title');

        var imgSrc = $(this).children('span').children('img').attr("src");
        if(imgSrc){
            document.getElementById("attr_image").value=imgSrc;
            $("#bigImg").attr({"src": imgSrc ,"jqimg": imgSrc });
            $(".attrs_"+attr_name+" strong").text($(this).children('span').children('img').attr('alt'));
            //$(this).parents("ul").siblings("b").text(  $(this).children('span').children('img').attr('alt') );
        }else{
            $(".attrs_"+attr_name+" strong").text($(this).text());
            //$(this).parents("ul").siblings("strong").text(  $(this).text() );
        }

        total_price += price;
    });
    if (attr_id.length > 0) {
        attr_id = attr_id.substr(0, attr_id.length - 1);
    }
    if(document.form.mun.value=="" || document.form.mun.value==0){
        var mun=1;
    }
    else{
        var mun=document.form.mun.value;
    }
    $(".pro_head_title strong").text(  $(".pro_title .selected").text() );

    document.getElementById("pro_id").value=$(".pro_title .selected").children('span').attr('alt');
    //console.debug($(".pro_title .selected").children('span').attr('alt'));
    total_price = total_price * mun;
    //console.debug(total_price);
    $("div.pro_price span").text(total_price);
    $('#allprice').val(total_price);
    $('#attr_id').val(attr_id);

}

$(function(){
    $(".attrs li").click(function(){
        $(this).parents("ul").find('li').removeClass('selected');
        $(this).addClass('selected');
        upd_price();
    })
})
/*衣服颜色切换*/
$(function(){
    $(".attrs ul li img").click(function(){
        var imgSrc = $(this).attr("src");
        var i = imgSrc.lastIndexOf(".");
        var unit = imgSrc.substring(i);
        imgSrc = imgSrc.substring(0,i);
        var imgSrc_small = imgSrc + unit;
        var imgSrc_big = imgSrc + unit;
        $("#bigImg").attr({"src": imgSrc_small ,"jqimg": imgSrc_big });
        $("#thickImg").attr("href", imgSrc_big);
        var alt = $(this).attr("alt");
        $(".attrs b").text(alt);

        upd_price();
    });
});
$(function(){
    $(".pro_title li").click(function(){
        $(this).parents("ul").find('li').removeClass('selected');
        $(this).addClass('selected');
        document.getElementById("pro_id").value=$(this).children('span').attr('alt');

        upd_price();
    })
})
$(function(){
    $(".pro_title li span").click(function(){
        $(this).parents("ul").siblings("strong").text(  $(this).text() );
        $("div.pro_price span").text( $(this).attr('datavalue') );
        document.getElementById("allprice").value=$(this).attr('datavalue');
        document.getElementById("base").value=$(this).attr('datavalue');
        //document.getElementById("pro_ids").value=$(".pro_title .selected").children('span').attr('alt');
        upd_price();
    })
})
/*数量和价格联动*/
/*$(function(){
    var $span = $("div.pro_price span");
    var price = $span.text();
    $("#num_sort").change(function(){
        var num = $(this).val();
        var amount = num * price;
        $span.text( amount );
    }).change();
})*/
function addnumber(){
    $('#mun').val(parseInt($('#mun').val())+1);
    upd_price();
}



function minnumber(){
    if($('#mun').val()>1){
        $('#mun').val(parseInt($('#mun').val())-1);
        upd_price();
    }
}
function inputnumber(){
    var number=parseInt($('#mun').val());
    if(isNaN(number)||number<1){
        $('#mun').val('1');
        upd_price();
    }else{
        $('#mun').val(number);
    }
    upd_price();
}
jQuery(window).scroll(function() {
    var currTop = $(window).scrollTop()
    if (jQuery(this).scrollTop() > 1){
        var divTop = $("#zhiding").offset().top;
        if (currTop > divTop) {
            if (scroll) {
                jQuery('nav').addClass("sticky");
            }
        }else{
            jQuery('nav').removeClass("sticky");
        }
    }
    else{
        jQuery('nav').removeClass("sticky");
    }
});


upd_price();
